package com.basic.business.finance.controller;


import java.util.List;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.finance.domain.TMoneyRules;
import com.basic.business.finance.service.ITMoneyRulesService;
import com.basic.common.core.page.TableDataInfo;

/**
 * 账单规则Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/moneyRules")
public class TMoneyRulesController extends BaseController
{
    @Resource
    private ITMoneyRulesService tMoneyRulesService;

    /**
     * 查询账单规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMoneyRules tMoneyRules)
    {
        List<TMoneyRules> list = tMoneyRulesService.getList(tMoneyRules);
        return getDataTable(list);
    }

    /**
     * 导出账单规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:export')")
    @Log(title = "账单规则", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "账单规则.xlsx")
    @PostMapping("/export")
    public String export(TMoneyRules tMoneyRules) throws IOException
    {
        List<TMoneyRules> list = tMoneyRulesService.getList(tMoneyRules);
        return EasyExcelUtils.excelExport(TMoneyRules.class,"账单规则数据", list);
    }

    /**
     * 获取账单规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tMoneyRulesService.get(id));
    }

    /**
     * 新增账单规则
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:add')")
    @Log(title = "账单规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMoneyRules tMoneyRules)
    {
        return toAjax(tMoneyRulesService.insert(tMoneyRules));
    }

    /**
     * 修改账单规则
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:edit')")
    @Log(title = "账单规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMoneyRules tMoneyRules)
    {
        return toAjax(tMoneyRulesService.update(tMoneyRules));
    }

    /**
     * 删除账单规则
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:remove')")
    @Log(title = "账单规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tMoneyRulesService.deleteByIds(ids));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:refreshCache')")
    @Log(title = "账单规则", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache(){
        tMoneyRulesService.loadingCache();
        return success();
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:moneyRules:changeStatus')")
    @Log(title = "账单规则", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tMoneyRulesService.updateStatusByIds(ids, status));
    }
}
